package com.gzx.plugin.data.core.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

//MD5
public class MD5Utils {
    public static String toMD5(String originalString) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");// 创建MD5消息摘要实例
            md.update(originalString.getBytes()); // 更新消息摘要
            byte[] digest = md.digest();// 获取摘要字节数组

            // 将字节转换为十六进制字符串
            StringBuilder sb = new StringBuilder();
            for (byte b : digest) {
                sb.append(String.format("%02x", b & 0xff));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("Could not find MD5 algorithm", e);
        }
    }
}
